package bank
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import utils.DisplayTool;
	
	import view.components.RemoteHtmlImg;
	import view.components.list.ITileListItem;
	
	public class ItemBankFriend extends Sprite implements ITileListItem
	{
		private var bankLandControl:BankLandControl = BankLandControl.getInstance();
		private var _index:int;
		private var _data:Object;
		private var _selected:Boolean;
		
		private var levelText:TextField;
		private var nameText:TextField;
		private var rankText:TextField;
		private var face:RemoteHtmlImg;
		
		public function ItemBankFriend()
		{
			this.mouseChildren = false;
			this.buttonMode = true;
			initText();
			initFace();
		}
		
		public function switchState(state:int):void
		{}
		
		private function initFace():void
		{
			face = new RemoteHtmlImg(20,20);
			face.x = 22;
			addChild(face);
		}
		
		private function initText():void
		{
			rankText = new TextField();
			rankText.width = 20;
			rankText.height = 20;
			rankText.x = 0;
			rankText.selectable = false;
			addChild(rankText);
			
			nameText = new TextField();
			nameText.x = 45;
			nameText.width = 65;
			nameText.height = 20;
			addChild(nameText);
			
			levelText = new TextField();
			levelText.x = 105;
			levelText.width = 30;
			levelText.height = 20;
			addChild(levelText);
			
			var tf:TextFormat = new TextFormat();
			tf.size = 14;
			tf.bold = true;
			rankText.defaultTextFormat = tf;
			
			tf.size = 12;
			tf.color = 0xFFFFFF;
			tf.bold = false;
			nameText.defaultTextFormat = tf;
			
			tf.color = 0xFF0000;
			levelText.defaultTextFormat = tf;
			
		}
		
		public function get self():DisplayObject
		{
			return this;
		}
		
		public function update(data:Object):void
		{
			_data = data;
			
			nameText.text = data.@name;
			levelText.text = data.@value + "级";
			face.loadImg(data.@image);
		}
		
		public function drawSelectBg():void
		{
			with(this.graphics)
			{
				clear();
				beginFill(0xFFFFFF,.5);
				drawRect(0,0,150,20);
				endFill();
			}
			
			bankLandControl.loadBankInfo(_data.@friendId);
		}
		
		public function drawOverBg():void
		{
		}
		
		public function drawOutBg():void
		{
			if (_selected)
			{
				return;
			}
			this.graphics.clear();
		}
		
		public function get selected():Boolean
		{
			return _selected;
		}
		
		public function set selected(v:Boolean):void
		{
			_selected = v;
		}
		
		public function get data():Object
		{
			return _data;
		}
		
		public function get index():int
		{
			return _index;
		}
		
		public function set index(v:int):void
		{
		
			if (v <= 3)
			{
				rankText.textColor = 0xFFFF00;	
			}
			else
			{
				rankText.textColor = 0xFFFFFF;
			}
			
			rankText.text = (v + 1).toString();
			_index = v;
		}
		
		public function destroy():void
		{
			DisplayTool.removeAllChild(this);
			nameText = null;
			rankText = null;
			levelText = null;
		}
		
		public function getInstance():ITileListItem
		{
			return new ItemBankFriend();
		}
		
		
	}
}